using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class Race : EveProperty
    {
        private string raceName;
        private string description;
        private int baseSkillTypeId;
        private int graphicId;
        private string shortDescription;

        private Type baseSkill;
        private List<RaceSkill> skills;
        private Graphic graphic;

        public string Name
        {
            get { return raceName; }
        }
        public string Description
        {
            get { return description; }
        }
        public Type BaseSkill
        {
            get
            {
                if (baseSkill == null)
                    baseSkill = new Type(db, baseSkillTypeId);
                return baseSkill;
            }
        }
        public Graphic Graphic
        {
            get
            {
                if (graphic == null)
                    graphic = new Graphic(db, graphicId);
                return graphic;
            }
        }
        public string ShortDescription
        {
            get { return shortDescription; }
        }
        public List<RaceSkill> Skills
        {
            get
            {
                if (skills == null)
                {
                    skills = new List<RaceSkill>();
                    string query = "SELECT * FROM chrRaceSkills WHERE raceID=" + Id;
                    foreach (DbDataRow row in db.ExecuteQuery(query))
                        skills.Add(new RaceSkill(row, this));
                }
                return skills;
            }
        }

        internal Race(DbDataRow dr)
            : base(dr.Database, EvePropertyType.Race, dr["raceID"])
        {
            Fill(dr);
        }
        internal Race(Database db, int id)
            : base(db, EvePropertyType.Race, id)
        {
            Fill(db.ExecuteSingle("SELECT * FROM chrRaces WHERE raceID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            raceName = dr["raceName"];
            description = dr["description"];
            baseSkillTypeId = dr["skillTypeID1"];
            graphicId = dr["graphicID"];
            shortDescription = dr["shortDescription"];
        }
    }
}
